#include "docclient.h"
#include "ui_docclient.h"

DocClient::DocClient(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::DocClient)
{
    emit doc_OnLoad();
}
void DocClient::Test()
{
    QMessageBox::information(this,"Test msg","Only For Test Usage =)");
}
void DocClient::doc_OnPreferences()
{
    if(this->doc_properties)
    {
        this->doc_properties->view();
    }
    else
    {
        QMessageBox::critical(this,"Error!!!","Error in :\n DocClient::doc_OnPreferences()");
    }

}
void DocClient::doc_OnAbout()
{
    //Show About
    QMessageBox::about(this,"About","It's My First Big Project=)");
}
void DocClient::doc_OnAbout_Qt()
{
    //Show About QT
    QMessageBox::aboutQt(this);
}
void DocClient::doc_OnExit()
{
    this->close();
}
void DocClient::doc_OnReload()
{
    emit doc_OnClose();
    emit doc_OnLoad();
}
void DocClient::doc_OnLoad()
{
    //Main Setup UI
    ui->setupUi(this);
    //Creating Objects
    this->doc_properties = new Propeties(this);
    this->doc_notes_grid = new QGridLayout(this->ui->widget);
    this->doc_notes = new notes();//(this->ui->widget);
    this->doc_config = new int;
    this->doc_errors = new int;
    //Setting Up User Interface
    this->doc_notes_grid->setSpacing(1);
    this->doc_notes_grid->setContentsMargins(0,0,0,0);
    this->doc_notes_grid->setObjectName(QString::fromUtf8("gridLayout_2"));
    this->doc_notes_grid->addWidget(this->doc_notes, 0, 0, 1, 1);
    this->doc_notes->show();

    //Menu Actions Connections =)
    connect(this->ui->actionOptions, SIGNAL(triggered()), this, SLOT(doc_OnPreferences()));
    connect(this->ui->actionAbout, SIGNAL(triggered()), this, SLOT(doc_OnAbout()));
    connect(this->ui->actionAbout_QT, SIGNAL(triggered()), this, SLOT(doc_OnAbout_Qt()));
    connect(this->ui->actionExit, SIGNAL(triggered()), this, SLOT(doc_OnExit()));
    connect(this->ui->actionReload, SIGNAL(triggered()), this, SLOT(doc_OnReload()));
}
void DocClient::doc_OnClose()
{
    //Disconnecting Slots
    disconnect(this, SLOT(doc_OnPreferences()));
    disconnect(this, SLOT(doc_OnAbout()));
    disconnect(this, SLOT(doc_OnAbout_Qt()));
    disconnect(this, SLOT(doc_OnExit()));
    disconnect(this, SLOT(doc_OnReload()));
    //Deleting Objects
    delete this->doc_properties;
    delete this->doc_notes_grid;
    delete this->doc_notes;
    delete this->doc_config;
    delete this->doc_errors;
    //Deleting All Widgets From Centralwidget
    foreach(QObject *tmp,this->centralWidget()->children())
    {
        delete tmp;
    }
    //Dleting All Menus =)
}
DocClient::~DocClient()
{
    emit doc_OnClose();
    delete ui;
}
